<template>
    <HomePanel title="人气推荐" sub-tittle="人气爆款,不容错过">
        <div class="hotContent">
            <div class="content" v-for="item in hotDataList" :key="item.id">
                <router-link to="">
                    <div class="img" @mouseover="hoveredItem = item.id" @mouseleave="hoveredItem = null">
                        <img v-img-lazy ="item.picture" :class="{ 'hovered': hoveredItem === item.id }" alt="">
                    </div>  
                    <div class="detail">
                        <div class="title">{{ item.title }}</div>
                        <p class="alt">{{ item.alt }}</p>
                    </div>
                </router-link>
            </div>
        </div>
    </HomePanel>
</template>

<script setup>
import { onMounted, ref } from 'vue';
import HomePanel from '../components/HomePanel.vue';
import { getHotAPI } from '@/apis/home';

const hotDataList = ref([]);
const hoveredItem = ref(null); // 用于跟踪当前悬停的项目

const getHot = async () => {
    const res = await getHotAPI();
    hotDataList.value = res.result;
};

onMounted(() => {
    getHot();
});
</script>

<style lang="scss" scoped>
.hotContent {
    padding: 10px 30px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 5px;
    background: #fff;

    .content {
        display: flex; 
        flex-direction: column;
        align-items: center; 
        width: 100%;
        height: 450px;

        .img {
            text-align: center;
            width: 300px;
            height: 300px;
            transition: transform 0.2s; /* 添加过渡效果 */
            margin: 10px 20px;
            img {
                width: 100%;
                height: 100%;
                border-radius: 10px;
                object-fit: cover; /* 确保图片覆盖整个容器 */
                transition: transform 0.2s; /* 添加过渡效果 */
            }

            /* 当 hoveredItem 匹配时，应用抬起效果 */
            img.hovered {
                transform: translateY(-5px); /* 向上抬起5px */
            }
        }
        .detail {
            margin-top: 10px;
            width: 350px;
            height: 95px;
            border-radius: 20px;
            display: flex;
            flex-direction: column;
            align-items: center; 
            justify-content: center;

            .title {
                text-align: center;
                margin-top: 10px;
                font-size: 25px;
                font-weight: bold;
            }

            .alt {
                text-align: center;
                padding-top: 10px;
                font-size: 22px;
                color: #ccc;
            }
        }
        
    }
}
</style>